<?php

declare(strict_types=1);

namespace app\admin\controller\dynamic;


use think\response\Json;
use app\admin\controller\Controller;

class Dynamic extends Controller
{
    /**
     * @var \app\admin\service\dynamic\DynamicService
     */
    protected $service = null;

    public function initialize()
    {
        parent::initialize();
        $this->service = new \app\admin\service\dynamic\DynamicService();
    }

    /**
     * 列表
     * @return Json
     * @throws \think\db\exception\DbException
     */
    public function list(): Json
    {
        return success($this->service->list());
    }

    public function detail(int $id): Json
    {
        return success($this->service->detail($id));
    }

    public function create(): Json
    {
        return success('发布成功', $this->service->create(request()));
    }

    public function update( ): Json
    {
        return success('更新成功', $this->service->update( request()));
    }

    public function delete(): Json
    {
        $id = $this->request->param('id', 0, 'intval');
        return $this->service->delete($id);
    }

    public function comment(): Json
    {
        return success($this->service->comment());
    }
    public function edit_comment(int $id): Json
    {
        return success('操作成功', $this->service->edit_comment($id, request()->param()));
    }

    public function del_comment(int $id): Json
    {
        return $this->service->del_comment($id);
    }

    public function select(): Json
    {
        return success($this->service->select());
    }
}
